package com.cskaoyan.service.systemservice;

import com.cskaoyan.bean.mallbean.Storage;
import com.cskaoyan.bean.systembean.Log;
import com.cskaoyan.bean.systembean.LogExample;
import com.cskaoyan.mapper.systemmapper.LogMapper;
import com.cskaoyan.vo.systemvo.LogVo;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class LogServiceImpl implements LogService {
    @Autowired
    LogMapper logMapper;


    /**
     * @param page  页数
     * @param limit 每页内容数
     * @param sort  排序的根据
     * @param order 正序or倒叙
     * @return 返回vo
     */
    @Override
    public LogVo list(Integer page, Integer limit, String name, String sort, String order) {
        //设置排序规则
        LogExample logExample = new LogExample();
        if (name != null && !"".equals(name)) {
            LogExample.Criteria criteria = logExample.createCriteria();
            criteria.andAdminLike("%" + name + "%");
        }
        logExample.setOrderByClause(sort + " " + order);

        //得到数据集
        List<Log> logs = logMapper.selectByExample(logExample);
        LogVo logVo = new LogVo();
        int size = logs.size();
        logVo.setTotal(size);
        //设置分页
        PageHelper.startPage(page, limit);
        logVo.setItems(logs);
        return logVo;
    }



}
